<template>
  <el-row type="flex" justify="space-between" align="middle" style="height: 40px;width: 100%">
    <el-col> {{ treeNote.name }}</el-col>
    <el-col :span="4">
      <el-row type="flex" justify="end">
        <el-col>{{ treeNote.manager }}</el-col>
        <el-col>
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right" />
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="add">添加部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="edit">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" command="del">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>

<script>
import { delDeptmentList } from '@/api/department'
export default {
  props: {
    treeNote: {
      type: Object,
      default: () => ({})
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 点击下拉菜单
    async handleCommand(type) {
      if (type === 'add') {
      // 添加
        this.$emit('addDepts', this.treeNote)
      } else if (type === 'edit') {
      // 编辑
        this.$emit('EditDepts', this.treeNote.id)
      } else {
        // 提示是否删除
        await this.$confirm('确实删除部门?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
        // 删除接口
        const res = await delDeptmentList(this.treeNote.id)
        console.log(res)
        this.$emit('delDept')
        this.$message.success('删除部门成功')
      }
    }
  }
}
</script>

<style lang ='scss' scoped >

</style>
